let context = null
const initContext = (vue) => {
	context = vue;
}
//获取工单详情接口 服务工单详情.html
const woItemAsync = async (UserPhone, WoGuid, token) => {

	let IdentifyId = "WOItem";
	var objects = {
		'UserId': UserPhone,
		'WOGUID': WoGuid
	};
	let strObject = JSON.stringify(objects);
	let [error, result] = await context.commService.postEntityAsync(IdentifyId, strObject, token);
	if (!error && result.statusCode == 200) {
		return result.data;
	}
	return null;
}


//上门
const woFieldServiceAsync = async (WOFieldService, token) => {
	let IdentifyId = "WOFieldService";
	var objects = {
		'UserId': WOFieldService.UserId,
		'WOGUID': WOFieldService.WOGUID,
		'Longitude': WOFieldService.Longitude,
		'Latitude': WOFieldService.Latitude,
		'Location': WOFieldService.Location,
		'NewAddress': WOFieldService.NewAddress,
		'Milestone': WOFieldService.Milestone,
		'IsLocationSuccess': WOFieldService.IsLocationSuccess,
		'Remark': WOFieldService.Remark,
	};
	let strObject = JSON.stringify(objects);
	let [error, result] = await context.commService.postEntityAsync(IdentifyId, strObject, token);
	if (!error && result.statusCode == 200) {
		return result.data;
	}
	return null;
}

//预约
const WOAppointmentAsync = async (UserPhone, WOGUID, AppointmentTime, Remark, ReasonCodeId, token) => {
	let IdentifyId = "WOAppointment";
	var objects = {
		'UserId': UserPhone,
		'WOGUID': WOGUID,
		'AppointmentTime': AppointmentTime,
		'Remark': Remark,
		'ReasonCodeId': ReasonCodeId,
	};
	let strObject = JSON.stringify(objects);
	let [error, result] = await context.commService.postEntityAsync(IdentifyId, strObject, token);
	if (!error && result.statusCode == 200) {
		return result.data;
	}
	return null;
}

//返工=》原因代码列表
const ReasonCodeListAsync = async (UserPhone, ReasonCodeType, token,woId) => {
	let IdentifyId = "ReasonCodeList";
	var objects = {
		'UserId': UserPhone,
		'ReasonCodeType': ReasonCodeType,
	};
	if(woId)
	{
		objects.WoId = woId
	}
	let strObject = JSON.stringify(objects);
	let [error, result] = await context.commService.postEntityAsync(IdentifyId, strObject, token);
	if (!error && result.statusCode == 200) {
		return result.data;
	}
	return null;
}


//生成配件行
const CreateAssemblyBomAsync = async (UserPhone, WOGUID, token) => {
	let IdentifyId = "CreateAssemblyBom";
	var objects = {
		'UserId': UserPhone,
		'WOGUID': WOGUID,
	};
	let strObject = JSON.stringify(objects);
	let [error, result] = await context.commService.postEntityAsync(IdentifyId, strObject, token);
	if (!error && result.statusCode == 200) {
		return result.data;
	}
	return null;
}

//催单处理
const WOPushAsync = async (UserPhone, WOGUID, Remark, token) => {
	let IdentifyId = "WOPush";
	var objects = {
		'UserId': UserPhone,
		'WOGUID': WOGUID,
		'Remark': Remark,
	};
	let strObject = JSON.stringify(objects);
	let [error, result] = await context.commService.postEntityAsync(IdentifyId, strObject, token);
	if (!error && result.statusCode == 200) {
		return result.data;
	}
	return null;
}

//更新工单
const WOUpdateOrderAsync = async (updateOrderData, token) => {
	let IdentifyId = "WOUpdate";
	var objects = {
		'UserId': updateOrderData.UserId,
		'WOGUID': updateOrderData.WOGUID,
		'Remark': updateOrderData.Remark,
		'ReasonCodeId': updateOrderData.ReasonCodeId,
		'AccountName': updateOrderData.AccountName,
		'Mobilephone': updateOrderData.Mobilephone,
		'Mobilephone2': updateOrderData.Mobilephone2,
		'Telephone': updateOrderData.Telephone,
		'Street': updateOrderData.Street,
	};
	let strObject = JSON.stringify(objects);
	let [error, result] = await context.commService.postEntityAsync(IdentifyId, strObject, token);
	if (!error && result.statusCode == 200) {
		return result.data;
	}
	return null;
}
//咨询完工
const WOConsultFinishAsync = async(ConsultFinish,token)=>{
	
	let IdentifyId = "WOConsultFinish";
	let strObject = JSON.stringify(ConsultFinish);	
	let [error, result]  = await context.commService.postEntityAsync(IdentifyId,strObject,token);
	console.log(result);
	if(!error && result.statusCode == 200){
		return result.data;
	}
	return null;
}
//返工
const WOReworkAsync = async (UserPhone,WOGUID,ReasonCodeId,Remark,token)=>{
	let IdentifyId = "WORework";
	var objects = {
		'UserId':UserPhone,
		'WOGUID':WOGUID,
		'ReasonCodeId':ReasonCodeId,
		'Remark':Remark,
	};
	let strObject = JSON.stringify(objects);	
	let [error, result]  = await context.commService.postEntityAsync(IdentifyId,strObject,token);
	if(!error && result.statusCode == 200){
		return result.data;
	}
	return null;
}
const workorderdetailservice = {
	initContext,
	woItemAsync,
	woFieldServiceAsync,
	WOAppointmentAsync,
	ReasonCodeListAsync,
	CreateAssemblyBomAsync,
	WOPushAsync,
	WOUpdateOrderAsync,
	WOConsultFinishAsync,
	WOReworkAsync
}

export default workorderdetailservice
